package com.wxb.controller;

import com.wxb.common.core.utils.StringUtils;
import com.wxb.common.core.web.domain.AjaxResult;
import com.wxb.domain.MallRegionEntity;
import com.wxb.domain.SysRegionEntity;
import com.wxb.mapper.MallRegionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Date 2025-05-30 10:25
 * @Version 1.0
 * @Description
 * @ClassName MallRegionController
 **/
@RestController
@RequestMapping("/region")
public class MallRegionController {
    @Autowired
    private MallRegionMapper sysRegionMapper;
    @GetMapping("list")
    public Object list(@RequestParam Map<String, Object> params) {
        List<SysRegionEntity> regionEntityList = sysRegionMapper.queryList(params);
        List<MallRegionEntity> regionVoList = new ArrayList<MallRegionEntity>();
        if (null != regionEntityList && regionEntityList.size() > 0) {
            for (SysRegionEntity sysRegionEntity : regionEntityList) {
                regionVoList.add(new MallRegionEntity(sysRegionEntity));
            }
        }
        return AjaxResult.success(regionVoList);
    }

    @PostMapping("provinceList")
    public Object provinceList(@RequestParam Map<String, Object> params) {
        List<SysRegionEntity> regionEntityList = sysRegionMapper.queryList(params);
        List<MallRegionEntity> regionVoList = new ArrayList<MallRegionEntity>();
        if (null != regionEntityList && regionEntityList.size() > 0) {
            for (SysRegionEntity sysRegionEntity : regionEntityList) {
                regionVoList.add(new MallRegionEntity(sysRegionEntity));
            }
        }
        return AjaxResult.success(regionVoList);
    }

    @PostMapping("cityList")
    public Object cityList(@RequestParam Map<String, Object> params) {
        List<SysRegionEntity> regionEntityList = sysRegionMapper.queryList(params);
        List<MallRegionEntity> regionVoList = new ArrayList<MallRegionEntity>();
        if (null != regionEntityList && regionEntityList.size() > 0) {
            for (SysRegionEntity sysRegionEntity : regionEntityList) {
                regionVoList.add(new MallRegionEntity(sysRegionEntity));
            }
        }
        return AjaxResult.success(regionVoList);
    }

    @PostMapping("distinctList")
    public Object distinctList(@RequestParam Map<String, Object> params) {
        List<SysRegionEntity> regionEntityList = sysRegionMapper.queryList(params);
        List<MallRegionEntity> regionVoList = new ArrayList<MallRegionEntity>();
        if (null != regionEntityList && regionEntityList.size() > 0) {
            for (SysRegionEntity sysRegionEntity : regionEntityList) {
                regionVoList.add(new MallRegionEntity(sysRegionEntity));
            }
        }
        return AjaxResult.success(regionVoList);
    }

    @PostMapping("info")
    public Object info(Integer regionId) {
        SysRegionEntity regionEntity =sysRegionMapper.queryObject(regionId);
        return AjaxResult.success(new MallRegionEntity(regionEntity));
    }

    @PostMapping("regionIdsByNames")
    public Object regionIdsByNames(String provinceName, String cityName, String districtName) {
        Map<String, Integer> resultObj = new HashMap<String, Integer>();
        Integer provinceId = 0;
        Integer cityId = 0;
        Integer districtId = 0;
        if (null != provinceName) {
            //provinceId = sysRegionMapper.(provinceName);
        }
        if (null != provinceId && !StringUtils.isEmpty(cityName)) {
            //cityId = RegionCacheUtil.getCityIdByName(provinceId, cityName);
        }
        if (null != provinceId && null != cityId && !StringUtils.isEmpty(districtName)) {
            //districtId = RegionCacheUtil.getDistrictIdByName(provinceId, cityId, districtName);
        }
        resultObj.put("provinceId", provinceId);
        resultObj.put("cityId", cityId);
        resultObj.put("districtId", districtId);
        return AjaxResult.success(resultObj);
    }
}
